﻿/**
 * ...
 * @author Lobanov AV.
 */

package model 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import view.components.utils.Stats;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	import flash.display.Stage;
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	
	public class StageProxy extends Proxy implements IProxy 
	{
		
		public static const NAME:String = "StageProxy";
		
		private var _layers:Object;
		
		/*
		 * CONSTANT position of view instante
		 */
		public static const ROOT:String = "root layer";
		public static const MAIN_BG:String = "slide show and pattern bg layer";
		public static const FOOTER:String = "footer components layer";
		public static const CONTACTS:String = "contacts components layer";
		public static const MAIN_MENU:String = "main menu components layer";
		public static const PORTFOLIO:String = "portfolio components layer";
				
		
		public function StageProxy(data:Object = null) 
		{
			super(NAME, data);
			stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
			
			initScene();
			
			stage.addEventListener(Event.RESIZE, notifyStageChange);
		}
		
		private function initScene():void {
			_layers = { };
			
			stage.addChild( _layers[ROOT] = new MovieClip() );
			stage.addChild( _layers[MAIN_BG] = new MovieClip() );
			stage.addChild( _layers[FOOTER] = new MovieClip() );
			stage.addChild( _layers[CONTACTS] = new MovieClip() );
			stage.addChild( _layers[PORTFOLIO] = new MovieClip() );
			stage.addChild( _layers[MAIN_MENU] = new MovieClip() );
			
			// monitor statistic
			var stat:Stats = new Stats();
			stat.alpha = .2;
			stage.addChild(stat);
		}
		
		public function notifyStageChange(e : Event = null) : void {
			facade.sendNotification(ApplicationFacade.STAGE_IS_RESIZE, new Array(stage.stageWidth, stage.stageHeight ));
		}
		
		//----------------------------------
		//--------  GETTER method  ---------
		//----------------------------------
        public function get stage():Stage {
            return this.getData() as Stage; 
        } 
		
		public function getLayer(layerKey:String):Object {
			return _layers[layerKey] as Object;
		}
	}
}